# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Contributor: Jerome Leclanche <jerome@leclan.ch>

pkgbase=cascadia-code
pkgname=("ttf-${pkgbase}" "otf-${pkgbase}" "woff2-${pkgbase}")
pkgver=2111.01
pkgrel=1
pkgdesc="A monospaced font by Microsoft that includes programming ligatures"
arch=("any")
url="https://github.com/microsoft/cascadia-code"
license=("custom:OFL")
source=(
    "${pkgname}-${pkgver}-release.zip::https://github.com/microsoft/${pkgbase}/releases/download/v${pkgver}/CascadiaCode-${pkgver}.zip"
    "${pkgname}-${pkgver}.tar.gz::https://github.com/microsoft/${pkgbase}/archive/v${pkgver}.tar.gz"
)
sha256sums=('51fd68176dffb87e2fbc79381aef7f5c9488b58918dee223cd7439b5aa14e712'
            'fb1859ca3f475e5c5510a69824eeb4622a04d8733b3a26d9de58ae26162ad5b9')

function prepare() {
    cd "${srcdir}/otf/static"
    cp ./*.otf ../
}

function _package() {
    cd "${srcdir}/"

    local ext="${1%%-*}"
    local installdir="${ext^^}"
    local fonts=("${srcdir}/${ext}"/*."${ext}")

    # Install fonts
    install -d "${pkgdir}/usr/share/fonts/${installdir}"
    local font
    for font in "${fonts[@]}"; do
        install -m644 "${font}" "${pkgdir}/usr/share/fonts/${installdir}"
    done

    # Install license
    install -Dm644 "${srcdir}/${pkgbase}-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

for _pkgname in ${pkgname[@]}; do
    eval "function package_$_pkgname() { _package $_pkgname; }"
done
